package com.ruoyi.web.controller.app;


import com.ruoyi.common.core.page.PageResult;
import com.ruoyi.common.core.page.ResponseResult;
import com.ruoyi.system.biz.BizOrderService;
import com.ruoyi.system.domain.Goods;
import com.ruoyi.system.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@Api(tags = "用户端:商品相关接口")
@RestController
@RequestMapping("public/app/goods")
public class GoodsController extends AppController {
    @Resource
    private GoodsService goodsService;

    @Resource
    private BizOrderService bizOrderService;

    @ApiOperation(value = "商品列表")
    @GetMapping("page")
    public ResponseResult<PageResult<Goods>> page() {
        startPage();
        List<Goods> list = goodsService.findList(new Goods());
        PageResult<Goods> pageResult = this.getPageResult(list);

        return this.setSuccessResult(pageResult);
    }

//    @ApiOperation(value = "商品详情")
//    @GetMapping("detail")
//    public ResponseResult<Goods> detail(Long id) {
//        Goods goods = this.goodsService.getById(id);
//        return this.setSuccessResult(goods);
//    }

    @ApiOperation(value = "删除")
    @GetMapping("getByPrice")
    public ResponseResult delById(BigDecimal price) {

        Goods byPrice = goodsService.getByPrice(price);


        return this.setSuccessResult(byPrice);
    }

    @ApiOperation(value = "填充数据")
    @RequestMapping("/insertGoods")
    public void insertGoods() throws Exception {
        bizOrderService.insertGoods();
    }

}
